These samples show how to construct XML elements and documents from code using LINQ to XML.

[Category("Construction")]
[Description("Computed element name")]
public void XLinq8()
{
XDocument customers = XDocument.Load("nw_customers.xml");
string name = (string)customers.Elements("Root")
.Elements("Customers")
.First()
.Attribute("CustomerID");
XElement result = new XElement(name,
"Element with a computed name");
Console.WriteLine(result);
}
[Category("Construction")] [Description("Computed element name")] public void XLinq8() { XDocument customers = XDocument.Load("nw_customers.xml"); string name = (string)customers.Elements("Root") .Elements("Customers") .First() .Attribute("CustomerID"); XElement result = new XElement(name, "Element with a computed name"); Console.WriteLine(result); }
For more information on LINQ to XML: http://msdn.microsoft.com/en-us/library/bb387098.aspx